home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / raytrace / radiance / simplerd.lha / simplerad / FinalFTP / Light / misc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-21  |  4.0 KB  |  111 lines

  1. /**********************************************************************/
  2. /* misc.h : miscellaneous variables and constants                     */
  3. /*                                                                    */
  4. /* Copyright (C) 1992, Bernard Kwok                                   */
  5. /* All rights reserved.                                               */
  6. /* Revision 1.0                                                       */
  7. /* May, 1992                                                          */
  8. /**********************************************************************/
  9. #ifndef MISC_H
  10. #define MISC_H
  11.  
  12. /* Miscellaneous constants */
  13. #define ERROR -1
  14. #define OK 1
  15. #define TRUE 1
  16. #define FALSE 0
  17. #define NULL 0
  18.  
  19. /**********************************************************************/
  20. /* Numerical constants */
  21. /**********************************************************************/
  22. #define ZERO         0
  23. #define POSITIVE     1
  24. #define NEGATIVE     -1
  25. #define VERY_SMALL       (1e-5)
  26. #define DAMN_SMALL       (1e-10)
  27. #define VERY_LARGE       (1e+5)
  28. #define DAMN_LARGE       (1e+10)
  29. #define PI               (3.14159265358979323846)
  30. #define HALFLIFE         (-.69314718)
  31. #define PITIMES2     6.283185    /* 2 * pi */
  32. #define PIOVER2         1.570796    /* pi / 2 */
  33. #define EE         2.718282    /* e */
  34. #define SQRT2         1.414214    /* sqrt(2) */
  35. #define SQRT3         1.732051    /* sqrt(3) */
  36. #define GOLDEN         1.618034    /* the golden ratio */
  37. #define DTOR         0.017453    /* convert degrees to radians */
  38. #define RTOD         57.29578    /* convert radians to degrees */
  39.  
  40. /**********************************************************************/
  41. /* Geometrical constants */
  42. /**********************************************************************/
  43. /* #define X 0
  44.    #define Y 1
  45.    #define Z 2
  46. */
  47. #define ANGLE_SHOCK_ABSORBER (0.4)
  48. #define COORD_SHOCK_ABSORBER (0.04)
  49. #define MIN_VECTOR_LENGTH    (1.0e-7)      /* min length of a vector */
  50. #define UP    1                          /* define up / down direction */
  51. #define DOWN    2
  52. #define UNIVERSE         (1e10)            /* maximum environment size */
  53. #define MAX_RESOLUTION   (4096)            /* maximum screen resolution */
  54.  
  55.  
  56. #define ABS(x)           (((x) > 0) ? (x) : (0 - (x)))
  57. #define FABS(a)         (((a) >= 0.0) ? (a): (-a))
  58. #define SCAN_INT(a,b)     (a == NULL ? 0 : sscanf(a,"%ld",b))
  59. #define FLOOR(a)     ((a)>0 ? (int)(a) : -(int)(-a))
  60. #define CEILING(a)  ((a)==(int)(a) ? (a) : (a)>0 ? 1+(int)(a) : -(1+(int)(-a)))
  61. #define ROUND(a)    ((a)>0 ? (int)(a+0.5) : -(int)(0.5-a))        
  62. #define ZSGN(a)        (((a)<0) ? -1 : (a)>0 ? 1 : 0)    /* sign of -1,0,1 */
  63. #define BSGN(a)        (((a) < -DAMN_SMALL) ? NEGATIVE : \
  64.               (a) > DAMN_SMALL ? POSITIVE : ZERO)
  65. /* take binary sign of a, either -1, or 1 if >= 0 */
  66. #define SGN(a)        (((a)<0) ? -1 : 0)
  67. /* shout if something that should be true isn't */
  68. #define ASSERT(x) \
  69. if (!(x)) fprintf(stderr," Assert failed: x\n");
  70. /* square a */
  71. #define SQR(a)        ((a)*(a))    
  72.  
  73. #define MIN(a,b)    (((a)<(b))?(a):(b))    
  74. #define MAX(a,b)    (((a)>(b))?(a):(b))    
  75. #define SWAP(a,b)    { a^=b; b^=a; a^=b; }
  76. /* linear interpolation from l (when a=0) to h (when a=1)*/
  77. /* (equal to (a*h)+((1-a)*l) */
  78. #define LERP(a,l,h)    ((l)+(((h)-(l))*(a)))
  79. /* clamp the input to the specified range */
  80. #define CLAMP(v,l,h)    ((v)<(l) ? (l) : (v) > (h) ? (h) : v)
  81.  
  82. #define MAX_ARG        25
  83. #define CONTINUE 0
  84. #define DIE 1
  85.  
  86. /**********************************************************************/
  87. /* memory allocation macros */
  88. /**********************************************************************/
  89. /* create a new instance of a structure (see Gem by Hultquist) */
  90. #define NEWSTRUCT(x)    (struct x *)(malloc((unsigned)sizeof(struct x)))
  91. /* create a new instance of a type */
  92. #define NEWTYPE(x)    (x *)(malloc((unsigned)sizeof(x)))
  93.  
  94. /**********************************************************************/
  95. /* String to HEX conversion */
  96. /**********************************************************************/
  97. /* unsigned int atox(s)
  98.     char *s;
  99. {
  100.   unsigned int x;
  101.  
  102.   if ((isalpha(s[0])) || ((strncmp(s,"0x",2) == 0) && (s += 2))) {
  103.     sscanf(s,"%x",&x);
  104.   } else
  105.     sscanf(s,"%u",&x);
  106.   return x;
  107. }
  108. */
  109.  
  110. #endif /* MISC_H */
  111.